		TITLE	DO_FN - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	IO_STRUC

		PUBLIC	DO_FILENAME,DO_DEFAULTS


		.DATA

		EXTERNDEF	FILNAM:NFN_STRUCT,SRCNAM:NFN_STRUCT

		EXTERNDEF	FILESTUFF_PTR:DWORD


		.CODE	FILEPARSE_TEXT

		EXTERNDEF	_parse_filename:proc,_check_nul1:proc,_move_srcprim_to_eax:proc

		public _do_defaults
_do_defaults	proc
	mov	EAX,8[ESP]
	mov	ECX,4[ESP]
	jmp	DO_DEFAULTS
_do_defaults	endp

		public _do_filename
_do_filename	proc
	mov	EAX,8[ESP]
	mov	ECX,4[ESP]
_do_filename	endp

DO_FILENAME	PROC
		;
		;EAX IS FILESTUFF_PTR
		;ECX IS NFN_STRUCT
		;
		PUSHM	ECX,EAX
		MOV	EAX,ECX
		push	EAX
		call	_parse_filename
		add	ESP,4
		POPM	EAX,ECX
		;
		;DEAL WITH DEFAULTS
		;
DO_DEFAULTS	LABEL	PROC
		;
		;EAX IS FILESTUFF_PTR
		;ECX IS NFN_STRUCT
		;
		PUSH	ESI
		MOV	ESI,ECX
		ASSUME	ESI:PTR NFN_STRUCT

		PUSH	EDI
		MOV	EDI,EAX
		ASSUME	EDI:PTR CMDLINE_STRUCT

		MOV	AL,[ESI].NFN_FLAGS

		TEST	EAX,MASK NFN_PRIM_SPECIFIED
		JZ	L1$
L19$:
		TEST	EAX,MASK NFN_EXT_SPECIFIED
		JNZ	L3$
		;
		;MOVE DEFAULT EXTENT (UNLESS PRIMARY IS NUL)
		;
		MOV	EAX,ESI
		push	EAX
		call	_check_nul1
		add	ESP,4
		test	EAX,EAX
		jnz	L3$		; it's NUL
		MOV	EDX,ESI
		ASSUME	EDX:PTR NFN_STRUCT
		;
		;MOVE DEFAULT EXTENT...
		;
		MOV	ESI,[EDI].CMD_EXTENT
		XOR	EAX,EAX
		MOV	AL,[ESI]
		INC	ESI
		MOV	ECX,EAX
		SUB	EAX,[EDX].NFN_EXTLEN
		MOV	[EDX].NFN_EXTLEN,ECX
		ADD	[EDX].NFN_TOTAL_LENGTH,EAX
		MOV	EAX,[EDX].NFN_PATHLEN
		LEA	EDI,[EDX].NFN_TEXT
		ADD	EAX,[EDX].NFN_PRIMLEN
		ADD	EDI,EAX
		REP	MOVSB
		MOV	DPTR [EDI],ECX
		MOV	ESI,EDX
L3$:
		POP	EDI
		MOV	EAX,ESI
		POP	ESI
		RET

L1$:
		;
		;NO PRIMARY FILENAME, MOVE EITHER NUL OR SRC...
		;
		PUSH	EAX
		CALL	[EDI].CMD_SELECTED
		JNZ	L13$			;WANT IT, MOVE SOURCE NAME
		;
		;OK, IF PATH OR EXTENTION SPECIFIED, MOVE SOURCE TOO
		;
		TEST	BPTR [ESI].NFN_FLAGS,MASK NFN_PATH_SPECIFIED+MASK NFN_EXT_SPECIFIED
		JZ	L15$
L13$:
		MOV	EAX,ESI

		push	EAX
		call	_move_srcprim_to_eax
		add	ESP,4
L15$:
		POP	EAX
		JMP	L19$

DO_FILENAME	ENDP

		END

